package com.googlecode.aredis.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.googlecode.aredis.CommandEncoder;
import com.googlecode.aredis.Protocol;

public class ZParams {
	public enum Aggregate {
		SUM, MIN, MAX;

		public final byte[] v;

		Aggregate() {
			v = CommandEncoder.encode(name());
		}
	}

	private List<byte[]> params = new ArrayList<byte[]>();

	public ZParams weights(final int... weights) {
		params.add(Protocol.Keyword.WEIGHTS.v);
		for (final int weight : weights) {
			params.add(Protocol.toByteArray(weight));
		}

		return this;
	}

	public Collection<byte[]> getParams() {
		return Collections.unmodifiableCollection(params);
	}

	public ZParams aggregate(final Aggregate aggregate) {
		params.add(Protocol.Keyword.AGGREGATE.v);
		params.add(aggregate.v);
		return this;
	}
}
